package com.yiqi.liebang.feature.order;

import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.suozhang.framework.utils.T;
import com.tbruyelle.rxpermissions2.RxPermissions;
import com.yiqi.liebang.R;
import com.yiqi.liebang.common.widget.dialog.BaseDialog;
import com.yiqi.liebang.common.widget.dialog.BounceTopEnter;
import com.yiqi.liebang.common.widget.dialog.SlideBottomExit;
import com.yiqi.liebang.entity.bo.UserCenterBo;
import com.yiqi.liebang.feature.mine.view.TopicListDialog;

import static android.content.Context.CLIPBOARD_SERVICE;

public class PhoneDialog extends BaseDialog<TopicListDialog> {

    private ClipboardManager myClipboard;
    private ClipData myClip;
    ImageView mBtnShareDialogCirclelose;

    private Activity context;
    private String phone;
    TextView textView;
    TextView textCopy;
    TextView textDail;
    RxPermissions rxPermissions;
    View.OnClickListener onClickListener;
    public PhoneDialog(Activity context, String phone) {
        super(context);
        this.phone = phone;
        myClipboard = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE);
        rxPermissions = new RxPermissions(context);
    }

    public PhoneDialog(Activity context) {
        super(context);
    }

    @Override
    public View onCreateView() {
        showAnim(new BounceTopEnter());
        dismissAnim(new SlideBottomExit());
        View inflate = View.inflate(mContext, R.layout.dialog_phone, null);
        mBtnShareDialogCirclelose = inflate.findViewById(R.id.btn_topic_close);
        textView = inflate.findViewById(R.id.tv_phone);
        textCopy = inflate.findViewById(R.id.btn_phone_copy);
        textDail = inflate.findViewById(R.id.btn_phone_dail);
        return inflate;
    }

    @Override
    public void setUiBeforShow() {
        textView.setText(phone);

        mBtnShareDialogCirclelose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

        textCopy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                myClip = ClipData.newPlainText("text", phone);
                myClipboard.setPrimaryClip(myClip);
                T.showShort("文本已复制！");
            }
        });
        textDail.setOnClickListener(onClickListener);

    }

   public void setDialClick(View.OnClickListener onClickListener){
        this.onClickListener=onClickListener;
    }


    public class TopicDialogAdapter extends BaseQuickAdapter<UserCenterBo.TopicBean, BaseViewHolder> {
        public TopicDialogAdapter() {
            super(R.layout.item_topic_dialog);
        }

        @Override
        protected void convert(BaseViewHolder helper, UserCenterBo.TopicBean item) {
            helper.setText(R.id.tv_topic_title, item.getTopicName()).setText(R.id.tv_topic_prize,
                    item.getTopicPrice() + "元/次");
        }
    }
}